package edu.uts.reekie.designer.execution.model.commands;

import edu.uts.reekie.designer.execution.actions.SetConnectorDecorationAction.End;
import edu.uts.reekie.designer.execution.model.Connector;
import edu.uts.reekie.designer.execution.model.Connector.Decoration;
import edu.uts.reekie.designer.model.AbstractDiagram;
import edu.uts.reekie.designer.model.ViewNode;

import org.eclipse.gef.commands.Command;
import org.eclipse.jface.fieldassist.DecoratedField;

public class SetConnectorDecorationCommand extends Command {

	private End ep;
	private Decoration newDec;
	private Decoration oldDec;
	
	private Connector conn;
	
	public Connector getConnector(){
		return conn;
	}
	public void setConnector(Connector c) {
		conn = c;
		
	}
	
	public SetConnectorDecorationCommand(End endPoint, Decoration decoration){
		ep= endPoint;
		newDec = decoration;
		
	}
	
	private void runy(boolean useNew){
		
		Decoration d = oldDec;
		if (useNew){
			d = newDec;
		}
		
		switch (ep){
		case Source:
						conn.setSourceDecoration(d);
						break;
		case Target:
			conn.setTargetDecoration(d);
			break;
		}
	}
	
	public void execute() {
		runy(true);
	}
	
	public void redo() {
		runy(true);
	}

	
	public void undo() {
		runy(false);
	}
}
